﻿//
// Created by Grishul Eugeny
//
// See license in License.txt
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace NCommander.Core
{
	public abstract class NodeProvider
	{
		public abstract Node[] Roots { get; }
		public abstract Node CurrentNode { get; set; }

		public abstract Node GetNode( string path );
		public abstract IEnumerable<Node> GetNodes();

		public virtual void OnView( Node[] nodes ) { }
		public virtual void OnEdit( Node[] nodes ) { }
		
		/// <summary>
		/// Used to delete nodes.
		/// </summary>
		/// <param name="nodes"></param>
		public virtual void OnDelete( Node[] nodes ) { }
		
		/// <summary>
		/// Used to show node options.
		/// </summary>
		/// <param name="node"></param>
		public virtual void OnOptions( Node node ) { }
		
		/// <summary>
		/// Used to excute node.
		/// </summary>
		/// <param name="node"></param>
		public virtual void OnExecute( Node node ) { }
		
		/// <summary>
		/// Used in diff operations for non-filesystem providers
		/// </summary>
		/// <param name="writer"></param>
		public virtual void CreateTextRepresentation( StreamWriter writer ) { }

		/// <summary>
		/// Invoked when nodes in CurrentNode changed
		/// </summary>
		public event EventHandler<RefreshEventArgs> Refresh = delegate { };

		public class RefreshEventArgs : EventArgs
		{
			public static readonly new RefreshEventArgs Empty = new RefreshEventArgs();

			public Node[] Added = null;
			public Node[] Removed = null;
			public Node[] Updated = null;
		}

		protected void InvokeRefresh() { Refresh( this, RefreshEventArgs.Empty ); }
		protected void InvokeRefresh( RefreshEventArgs args ) { Refresh( this, args ); }
	}
}
